//package com.pengzy.core.cloud_security;
//
//import cn.hutool.core.bean.BeanUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.pengzy.comment.mybatis.entity.SysUser;
//import com.pengzy.comment.mybatis.mapper.SysMenuMapper;
//import com.pengzy.comment.mybatis.mapper.SysUserMapper;
//import com.pengzy.supports.dto.UserDetail;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Mono;
//
//import javax.annotation.Resource;
//import java.util.Collection;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
///**
// * @author xiaozhi 2023/7/17
// */
//@Component
//@Slf4j
//public class SecurityUserDetailsService implements ReactiveUserDetailsService {
//
//    @Resource
//    private SysUserMapper sysUserMapper;
//    @Resource
//    private SysMenuMapper sysMenuMapper;
//
//    private final PasswordEncoder passwordEncoder= new BCryptPasswordEncoder();
//    @Override
//    public Mono<UserDetails> findByUsername(String username) {
//        log.info("findByUsername。。。。。。。。。。");
//        //根据用户名查询用户信息
//        SysUser user=getUser(username);
//        UserDetail detail= BeanUtil.toBean(user, UserDetail.class);
//        //TODO 根据用户查询权限信息 添加到LoginUser中
//        List<String> list=sysMenuMapper.menuList(user.getUserId());
//        SecurityUserDetails securityUserDetails = new SecurityUserDetails(detail,username,detail.getPassword(),getAuthUser(list));
//        return Mono.just(securityUserDetails);
//    }
//
//    public Collection<? extends GrantedAuthority> getAuthUser( List<String> list){
//        return list.stream().
//                map(SimpleGrantedAuthority::new)
//                .collect(Collectors.toList());
//    }
//
//
//    public SysUser getUser(String username){
//        LambdaQueryWrapper<SysUser> userLambdaQueryWrapper= Wrappers.lambdaQuery();
//        userLambdaQueryWrapper.eq(SysUser::getUserName,username)
//                .last("limit 1");
//        SysUser sysUser = sysUserMapper.selectOne(userLambdaQueryWrapper);
//        if(Objects.isNull(sysUser)){
//            throw new RuntimeException("用户或者密码为错误！");
//        }
//        return sysUser;
//    }
//}
